<template>
  <div class="full">
    <el-scrollbar>
      <div class="p-12">
        <CellBox title="成品型号">
          <TableBoxMx :data="{
            disabled: !isEdit,
            tbody: data.productSpecificationList,
            thead: [
              {
                label: '成品编码',
                prop: 'productSpecificationNumber',
                align: 'center',
                width: 200,
              },
              {
                label: '产品型号',
                prop: 'productSpecificationName',
                align: 'center',
                width: 200,
              },
              {
                label: '备注',
                prop: 'remark',
                align: 'left',
                width: null,
              },
            ],
            add: () => {
              proxy.$openPup(pupAdd, 1)
            }
          }">
          </TableBoxMx>
        </CellBox>
      </div>
    </el-scrollbar>
  </div>
  <ElPupFormBox :pup="pupAdd">
    <template #default="{ form }">
      <ElFormItemBox label="型号名称" :prop="`productSpecificationName`" isRules>
        <ElInputBox :data="form" dataName="productSpecificationName" />
      </ElFormItemBox>
      <ElFormItemBox label="备注" :prop="`remark`">
        <ElInputBox :data="form" dataName="remark" type="textarea" />
      </ElFormItemBox>
    </template>
  </ElPupFormBox>
</template>
<script setup lang="ts">
import '../pageCss.scss'; // 引入样式
const { proxy } = getCurrentInstance() as any;
const props = withDefaults(
  defineProps<{
    data?: any;//数据源
    isEdit?: boolean;//是否編輯
    options?: any;//数据组
    setState?: Function;//更改状态
  }>(),
  {
  },
);
const pupAdd: any = reactive({
  state: false,
  typeName: 0,
  title: `成品型号`,
  width: 500,
  height: 'auto',
  form: {
    productSpecificationID: 0, //主键
    productSpecificationCode: "", //型号编码（唯一标识）
    productCode: "", //产品编码
    productSpecificationNumber: "", //成品编号（展示字段）
    productSpecificationName: "", //型号名称
    isDisable: 0, //	启用状态
    remark: "" //	备注
  },
  btns: [
    {
      title: '保存',
      type: 'primary',
      click: (pup: any) => {
        pup.loading = true
        //新建
        proxy.$api.OrderBusniess.SaveProductSpecification({
          ...pup.form,
          productCode: proxy.data.baseData.productCode,
        })
          .then((res: any) => {
            pup.state = false
            proxy.$message(`保存成功`);
            saveBtn()
          }).catch(() => {
            pup.loading = false
          })
      }
    }
  ]
});
const emit = defineEmits<{
  //fn为父组件引入子组件是定义的子组件事件属性，可随意定义
  (event: 'saveBtn'): void;
}>();
const saveBtn = () => {
  emit('saveBtn')
}
onMounted(() => {
});
</script>
